package org.easy.tool.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Valley
 * Description
 * Created by Valley on 2025/6/16 18:32
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Value("${westudy.front-address}") private String frontAddress;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins(frontAddress) // 替换为你的前端域名
                .allowCredentials(true) // 允许凭证
                .allowedMethods("GET", "POST", "PUT", "DELETE");
    }
}